/////////////////////////////////////////////////////////////////////
// DBMysql.h
//
//
// 11/16/2010
//
/////////////////////////////////////////////////////////////////////

#ifndef __DBMYSQL_H__
#define __DBMYSQL_H__

#include <Mysql.h>



//typedef char				INT8;
//typedef unsigned char		UINT8;
//typedef short				INT16;
//typedef unsigned short		UINT16;
//typedef int					INT32;
//typedef unsigned int		UINT32;
//typedef __int64				INT64;
//typedef unsigned __int64	UINT64;

class DBMysql
{
public:
	DBMysql( void );

	bool Create( std::string ip, std::string username, std::string pwd, std::string db, short nPort );

	void Destroy( void );

public:

	int EscapeString( char * to, const char * from );

	int EscapeString( char * to, const void * from );

	INT64 Query( const char * sql );

	void FreeResult( void );

	bool GetRow( void );

	void GetField( UINT64 &data, int idx );
	void GetField( INT64 &data, int idx );
	
	void GetField( UINT32 &data, int idx );
	void GetField( INT32 &data, int idx );
	
	void GetField( UINT16 &data, int idx );
	void GetField( INT16 &data, int idx );

	void GetField( UINT8 &data, int idx );
	void GetField( INT8 &data, int idx );

	void GetField( bool &data, int idx );
	void GetField( char &data, int idx );

	void GetField( void * buffer, unsigned long len, int idx );
	void GetField( char * szString, unsigned long len, int idx );

	void GetField( string& str, int idx );

private:
	bool Create( void );

	std::string		m_ip;
	std::string		m_username;
	std::string		m_pwd;
	std::string		m_db;
	short			m_nPort;
	
	MYSQL			*m_mysql;
	MYSQL_RES		*m_curResult;
	MYSQL_ROW		m_curRow;

	INT64			m_nCurRows;
};


#endif // __DBMYSQL_H__